module alist
import StdEnv, japi

/* A ListBox (LB), allows you to choose
   from a list of options    */

:: State = {frame::!Framer, text::!LDev}

Start world
  # (js, world) = begin_japi world
    (frm, js) = jnewFrame  (WH 400 300) "Colors" js
    msg= "Double click your option"
    (lbl, js)= jnewLabel (XY 50 70) msg frm js
    lbl= jsetfont (Helvetia 20) lbl
    options= ["Blue", "Red", "Green", "Yellow", "White"]
    options= options++options
    (txt, js) = jnewLB (XY 100 150) 4  options frm js
    txt = jselect 0 txt
    //txt = jsetfont (TimesNew 20) txt
    (frm, js) = jshow frm js
    s= {frame= frm, text= txt}
    js= loop s js
  = end_japi js world
where
  loop :: !State !JapiState -> JapiState
  loop s js
     # (na, js) = jnextaction js
     | na== (act s.frame)= jquit js
     | na== (act s.text)
         # (t, txt)= jgetselect s.text
           frm= bg_color  (co!!t) s.frame
           txt= jdeselect t txt  
         = loop {s& frame= frm, text=txt } js
     = loop s js

co= [blue, red, green, yellow, white:co]
